import { App } from 'vue'
import router from '@/router'

export default {
  install: (app:App) => {
    app.directive('has', {
      mounted (el, binding) {
        let isExist = false
        const btnPermissions:Array<string> = <Array<string>>router.currentRoute.value.meta.btnPermissions

        if (btnPermissions && btnPermissions.indexOf(binding.value) > -1) {
          isExist = true
        }
        if (el.parentNode && !isExist) {
          el.parentNode.removeChild(el)
        }
      }
    })
  }
}
